const state = {
  userInfo: {
    name: 'mariao',
    age: 17
  },
  other: null
}
const mutations = {
  changeUser (state, obj) {
    state.userInfo = obj
  },
  changeOther (state, obj) {
    state.other = obj
  }
}
const actions = {
  changeUserAsync (context, obj) {
    setTimeout(() => {
      context.commit('changeUser', obj)
    }, 1000)
  },
  getUser (context) {
    fetch('http://localhost:3000/user').then((res) => {
      return res.json()
    }).then((res) => {
      console.log('res', res)
      context.commit('changeOther', res)
    })
  }
}
const getters = {
  getUpperName (state) {
    return state.userInfo.name.toUpperCase()
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
